package json

import "encoding/json"

func ToJson(v interface{}, pretty ...bool) string {
	if len(pretty) == 1 && pretty[0] {
		result, err := json.MarshalIndent(v, "", "    ")
		if err != nil {
			return ""
		}
		return string(result)
	} else {
		bytes, err := json.Marshal(v)
		if err != nil {
			return ""
		}
		return string(bytes)
	}
}
